package com.ruoyi.project.poem.guesssubject.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.guesssubject.domain.GuessSubject;
import com.ruoyi.project.poem.guesssubject.service.IGuessSubjectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 猜诗题目Controller
 * 
 * @author shixiangwen
 * @date 2021-02-10
 */
@Controller
@RequestMapping("/poem/guesssubject")
public class GuessSubjectController extends BaseController
{
    private String prefix = "poem/guesssubject";

    @Autowired
    private IGuessSubjectService guessSubjectService;

    @RequiresPermissions("poem:guesssubject:view")
    @GetMapping()
    public String guesssubject()
    {
        return prefix + "/guesssubject";
    }

    /**
     * 查询猜诗题目列表
     */
    @RequiresPermissions("poem:guesssubject:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GuessSubject guessSubject)
    {
        startPage();
        List<GuessSubject> list = guessSubjectService.selectGuessSubjectList(guessSubject);
        return getDataTable(list);
    }

    /**
     * 导出猜诗题目列表
     */
    @RequiresPermissions("poem:guesssubject:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GuessSubject guessSubject)
    {
        List<GuessSubject> list = guessSubjectService.selectGuessSubjectList(guessSubject);
        ExcelUtil<GuessSubject> util = new ExcelUtil<GuessSubject>(GuessSubject.class);
        return util.exportExcel(list, "guesssubject");
    }

    /**
     * 新增猜诗题目
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存猜诗题目
     */
    @RequiresPermissions("poem:guesssubject:add")
    @Log(title = "猜诗题目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GuessSubject guessSubject)
    {
        return toAjax(guessSubjectService.insertGuessSubject(guessSubject));
    }

    /**
     * 修改猜诗题目
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GuessSubject guessSubject = guessSubjectService.selectGuessSubjectById(id);
        mmap.put("guessSubject", guessSubject);
        return prefix + "/edit";
    }

    /**
     * 修改保存猜诗题目
     */
    @RequiresPermissions("poem:guesssubject:edit")
    @Log(title = "猜诗题目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GuessSubject guessSubject)
    {
        return toAjax(guessSubjectService.updateGuessSubject(guessSubject));
    }

    /**
     * 删除猜诗题目
     */
    @RequiresPermissions("poem:guesssubject:remove")
    @Log(title = "猜诗题目", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(guessSubjectService.deleteGuessSubjectByIds(ids));
    }
}
